package com.hongyuan.sellfitness.ui.person.activity;

import android.os.Bundle;

import androidx.lifecycle.ViewModelProviders;

import com.hongyuan.sellfitness.R;
import com.hongyuan.sellfitness.base.AppViewModelFactory;
import com.hongyuan.sellfitness.base.Constants;
import com.hongyuan.sellfitness.base.CustomActivity;
import com.hongyuan.sellfitness.databinding.ActivityMyOrderDetailsBinding;
import com.hongyuan.sellfitness.ui.person.view_mode.MyOrdersDetailViewModel;
import com.hongyuan.sellfitness.utils.CustomDialog;

import me.tatarka.bindingcollectionadapter2.BR;

public class MyOrderDetailActivity extends CustomActivity<ActivityMyOrderDetailsBinding, MyOrdersDetailViewModel> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_my_order_details;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public MyOrdersDetailViewModel initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(MyOrdersDetailViewModel.class);
    }

    @Override
    public void initView() {
        super.initView();
        setOnRefresh(binding.refresh,REFRESH_0X4);

        binding.comBack.setOnClickListener(view -> finish());
    }

    @Override
    public void initData() {
        super.initData();

        viewModel.clearParams().setParams("o_id",getBundle().getString("o_id")).setParams("type","pt");
        viewModel.requestData(Constants.GET_ORDER_INFO);
        //获取客服电话
        viewModel.requestData(Constants.GET_ONLINE_KF);
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();

        viewModel.uc.cancelOrder.observe(this, aVoid -> {
            CustomDialog.promptDialog(this, "确定要取消订单吗？", "确定！", "不确定？", false, v1 -> {
                if (v1.getId() == R.id.isOk) {
                    viewModel.setParams("o_id",String.valueOf(viewModel.entity.get().getO_id()));
                    viewModel.requestData(Constants.CANCEL_ORDER);
                }
            });
        });
    }
}
